package com.chenfei.captcha.controller;

import com.chenfei.captcha.common.MarketRespEnum;
import com.chenfei.captcha.req.CaptchaReq;
import com.chenfei.captcha.resp.BaseResEntity;
import com.chenfei.captcha.resp.ResponseEntity;
import com.chenfei.captcha.service.CaptchaService;
import com.spring4all.swagger.EnableSwagger2Doc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenfei
 * @description
 * @since 2018/4/4
 */
@RestController
@Slf4j
@EnableSwagger2Doc
public class CaptchaController {

    @Autowired
    CaptchaService captchaService;

    @GetMapping(value = "/getCaptcha")
    public BaseResEntity getCaptcha(){
        return captchaService.getCaptcha();
    }

    @PostMapping(value = "/verifyCaptcha")
    public BaseResEntity verifyCaptcha(@RequestBody CaptchaReq captchaReq){
        ResponseEntity responseEntity = new ResponseEntity(MarketRespEnum.SUCCESS);
        responseEntity.setData(captchaService.verifyCaptcha(captchaReq));
        return responseEntity;
    }
}
